Column

Chart A

Chart B

Column

Chart C

Chart D

---
title: "Dashboard"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    source: embed
---

```{r setup, include=FALSE}
library(tidyverse)
library(p8105.datasets)
library(plotly)

library(flexdashboard)
```


```{r}
data("rest_inspec")

nyc_inspect = 
  rest_inspec %>% 
  select(boro, cuisine_description, dba, score, violation_description, grade, building) %>% 
  filter(grade %in% c("A", "B", "C"))
```

Column {data-width=600}
-----------------------------------------------------------------------

### Chart A

```{r}
nyc_inspect %>% 
  filter(cuisine_description == c("Korean", "Thai", "Chinese", "Vietnamese", "Japanese", "Russian", "Italy", "French", "American", "Mexican")) %>% 
  filter(score %in% 20:50) %>% 
  mutate(text_label = str_c("Score: ", score)) %>%
  plot_ly(x = ~cuisine_description, y = ~dba, 
          type = "scatter", mode = "markers", text = ~text_label,
          color = ~score, colors = "viridis") %>% 
  layout(title = "Restaurants with score between 20 and 50",
         xaxis = list(title = "Cuisine"),
         yaxis = list(title = "Restaurant"))

nyc_inspect %>% 
  filter(score %in% 20:50) %>% 
  mutate(text_label = str_c("Score: ", score)) %>%
  plot_ly(x = ~building, y = ~score, 
          type = "scatter", mode = "markers", text = ~text_label,
          color = ~score, colors = "viridis") %>% 
  layout(title = "Restaurants with score between 20 and 50",
         xaxis = list(title = "Cuisine"),
         yaxis = list(title = "Restaurant"))
```

### Chart B

```{r}
nyc_inspect %>% 
  mutate(text_label = str_c("Restaurant: ", dba, "\nScore: ", score)) %>%
  plot_ly(x = ~score, type = "histogram", color = "orange", alpha = .8, text = ~text_label) %>% 
  layout(title = "Histogram of inspection scores of NY restaurants",
         xaxis = list(title = "Score"),
         yaxis = list(title = "Count"))
```

Column {data-width=400}
-----------------------------------------------------------------------

### Chart C

```{r}
nyc_inspect %>% 
  filter(cuisine_description == c("Korean", "Thai", "Chinese", "Vietnamese", "Japanese", "Russian", "Italy", "French", "American", "Mexican")) %>% 
  mutate(text_label = str_c("Restaurant: ", dba, "\nScore: ", score)) %>%
  plot_ly(y = ~score, x = ~cuisine_description, 
          color = ~cuisine_description, colors = "viridis",
          text = ~text_label,
          type = "box") %>% 
  layout(
    title = "Scores of restaurants in NY grouped by cuisine", 
    xaxis = list(title = "Cuisine"),
    yaxis = list(title = "Inspection score"))
```

### Chart D

```{r}
nyc_inspect %>% 
  filter(cuisine_description == c("Korean", "Thai", "French", "Pizza", "Italian", "Peruvian", "Geek", "Chinese", "Vietnamese", "Japanese", "Bakery", "Russian", "German", "Indian", "Delicatessen", "Café/Coffee/Tea", "Mexican", "American")) %>% 
  count(cuisine_description) %>% 
  mutate(cuisine_description = fct_reorder(cuisine_description, n)) %>% 
  plot_ly(x = ~cuisine_description, y = ~n, color = ~cuisine_description,
          type = "bar", colors = "viridis") %>% 
  layout(
    title = "Count of restaurants in Manhattan by cuisine", 
    xaxis = list(title = "Cuisine"),
    yaxis = list(title = "Count"))
```